<!--
title: 接口请求
description: 
published: true
date: 2025-06-17T04:26:54.968Z
tags: 
editor: ckeditor
dateCreated: 2025-06-17T04:26:54.968Z
-->

<h1>获取接口请求信息</h1>
<p>&nbsp;</p>
<pre><code class="language-plaintext"># 获取URL请求参数
id = request.args.get("id")

# 获取json请求体
data = request.get_json()

# 获取请求体
data = request.data  # 返回字节类型的请求体内容
data = request.get_data(as_text=True) # 返回字符串格式的请求体内容

# 获取表单数据（application/x-www-form-urlencoded 或 multipart/form-data）
form_data = request.form  # ImmutableMultiDict 类型，可以用 form_data.get('key') 获取具体字段</code></pre>
<p>&nbsp;</p>
<h2><strong>简单示例</strong></h2>
<p>&nbsp;</p>
<pre><code class="language-plaintext"># 以接口代码为例

# 获取 JSON
json_data = request.get_json()

# 获取原始数据
raw_data = request.data

# 获取表单数据
form_data = request.form

return {
    "json": json_data,
    "raw": raw_data.decode('utf-8'),
    "form": form_data.to_dict()
}1</code></pre>
<p>&nbsp;</p>
